﻿#region 命名空间

using System;
using System.Web;
using System.Web.UI.WebControls;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model;
using WinnerCMS.Model.Attribute;
using WinnerCMS.WebControls;
using WinnerCMS.WebFactory;

#endregion

namespace WinnerCMS.WebUI.Admin.ControlPanel
{
    /// <summary>
    ///     用户日志
    /// </summary>
    [Access("264003")]
    public partial class Log : PageBase
    {
        private readonly LogManage _myBll = new LogManage();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.btnDelete.Attributes.Add("onclick", "return confirm('您确定要删除？');");

                BindList(1);
            }
        }

        private void BindList(int pageNo)
        {
            this.GV_List.EmptyDataTemplate = GetTemplate(this);
            this.DL_LogChoose.DataSource = this._myBll.GroupBy();
            this.DL_LogChoose.DataBind();

            this.BC_Path.Items.Clear();
            this.BC_Path.Items.Add(new ListItem {Text = "日志管理", Value = "Log.aspx"});
            if (Request["Key"] != null)
            {
                this.BC_Path.Items.Add(new ListItem
                {
                    Text = HttpUtility.UrlDecode(Request.QueryString["Key"]),
                    Value = ""
                });
            }

            var pp = new PagingParam {PageSize = this.PageNavigation1.PageSize, PageNo = pageNo};

            this.GV_List.DataSource = this._myBll.BindList(true, Request.QueryString["Key"], pp);
            this.GV_List.DataBind();
            this.PageNavigation1.RecordCount = pp.RecordCount;
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            var IDs = GetSelectedRow.GetIDs(this.GV_List);
            var res = this._myBll.Delete(IDs);
            if (res.Errors.Length == 0)
            {
                MsgBox.Message("删除成功。", this.UpdatePanel1);
                BindList(1);
            }
            else
            {
                MsgBox.Message(res.Errors, this.UpdatePanel1);
            }
        }

        protected void PageNavigation1_PageChanging(object src, PageChangingEventArgs e)
        {
            BindList(e.NewPageIndex);
        }

        protected void btnClear_Click(object sender, EventArgs e)
        {
            this._myBll.Clear();
            BindList(1);
        }
    }
}